package com.tfswx.ruleengine.fn;

import com.greenpineyu.fel.context.FelContext;
import com.tfswx.ruleengine.compute.gzjy.BaseFn;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Ricky
 * @date 2021/4/28
 */
public class ToNum extends BaseFn {
    @Override
    public Object call(Object[] arguments, FelContext context) {
        String argument = String.valueOf(arguments[0]);
        if (StringUtils.isBlank(argument)) {
            return 0;
        }
        return Double.parseDouble(argument);
    }

    @Override
    public String getZwmc() {
        return "转为数字类型";
    }


    @Override
    public List<Param> getParams() {
        ArrayList<Param> params = new ArrayList<>();
        params.add(new Param("param1", "数字"));
        return params;
    }

    @Override
    public String getName() {
        return "toNum";
    }
}
